<?php
/**
 * 项目类型模型
 * @author qianxun
 *
 */
class proTypeModel extends MY_Model{
    function proTypeModel(){
        parent::MY_Model();
        $this->table='ProType';
        $this->load->library('Cache');
    }
    /**
     * 包装数据(non-PHPdoc)
     * @see MY_Model::packing()
     */
    function packing($list = array()){
        foreach ($list as $k => $v){
            $v['statusIsStr'] = $v['statusIs'] == 1 ? '使用中' :'关闭';
            $list[$k] = $v;
        }
        return $list;
    }
    /**
     * 创建项目类型缓存
     */
    function createCache(){
        $proTypeAllList = array();
        $proTypeList = array();
        $findList = $this->getList(array('proTypeId > '=>0), NULL, NULL, 'proTypeId,proTypeName,statusIs','orderNum ASC,proTypeId ASC');
        foreach ($findList as $v){
            if ($v['statusIs'] == 1){
                $proTypeList[(int)$v['proTypeId']] = $v;
            }
            $proTypeAllList[(int)$v['proTypeId']] = $v;                
        }
        //保存缓存
        $this->cache->set('proTypeList', $proTypeList);//缓存地区列表
        $this->cache->set('proTypeAllList', $proTypeAllList);//缓存地区列表
    }
    /**
     * 获取缓存数据
     * @param string $type
     * @return array
     */
    function getCacheData($type) {
        $this->cache->expire = 86400;//设置过期时间为一天
        $data = $this->cache->get($type);
        if (!$data){
            //创建缓存
            $this->createCache();
            $data = $this->cache->get($type);
        }
        return $data;
    }
}